package pl.prv.polanie.client.widgets.utils;



import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author Janusz Prokulewicz
 * Created: May 10, 2008
 */
public class Borders {
	
	public static final int BORDERS_GRAY = 0;
	public static final int BORDERS_RED = 1;
	public static final int BORDERS_BLACK = 2;
	public static final int BORDERS_BLUE = 3;
	
	
	
	
	//style do gray border
	private static final String STYLE__CALENDAR_DAY_GRAY_BORDER_TOP = "grayBorderTop";
	private static final String STYLE__CALENDAR_DAY_GRAY_BORDER_BOTTOM = "grayBorderBottom";
	private static final String STYLE__CALENDAR_DAY_GRAY_BORDER_LEFT = "grayBorderLeft";
	private static final String STYLE__CALENDAR_DAY_GRAY_BORDER_RIGHT = "grayBorderRight";

	public static void addGrayDashedBorders(AbsolutePanel ap) {
		BorderHTML borderTop = new BorderHTML(BORDERS_GRAY);
		borderTop.setStyleName(STYLE__CALENDAR_DAY_GRAY_BORDER_TOP);
		ap.add(borderTop);
		
		BorderHTML borderBottom = new BorderHTML(BORDERS_GRAY);
		borderBottom.setStyleName(STYLE__CALENDAR_DAY_GRAY_BORDER_BOTTOM);
		ap.add(borderBottom);
		
		BorderHTML borderLeft = new BorderHTML(BORDERS_GRAY);
		borderLeft.setStyleName(STYLE__CALENDAR_DAY_GRAY_BORDER_LEFT);
		ap.add(borderLeft);
		
		BorderHTML borderRight = new BorderHTML(BORDERS_GRAY);
		borderRight.setStyleName(STYLE__CALENDAR_DAY_GRAY_BORDER_RIGHT);
		ap.add(borderRight);
	}

	
	
	//style do red border
	private static final String STYLE__CALENDAR_DAY_RED_BORDER_TOP = "redBorderTop";
	private static final String STYLE__CALENDAR_DAY_RED_BORDER_BOTTOM = "redBorderBottom";
	private static final String STYLE__CALENDAR_DAY_RED_BORDER_LEFT = "redBorderLeft";
	private static final String STYLE__CALENDAR_DAY_RED_BORDER_RIGHT = "redBorderRight";
	
	public static void addRedDashedBorders(AbsolutePanel ap) {
		BorderHTML borderTop = new BorderHTML(BORDERS_RED);
		borderTop.setStyleName(STYLE__CALENDAR_DAY_RED_BORDER_TOP);
		ap.add(borderTop);
		
		BorderHTML borderBottom = new BorderHTML(BORDERS_RED);
		borderBottom.setStyleName(STYLE__CALENDAR_DAY_RED_BORDER_BOTTOM);
		ap.add(borderBottom);
		
		BorderHTML borderLeft = new BorderHTML(BORDERS_RED);
		borderLeft.setStyleName(STYLE__CALENDAR_DAY_RED_BORDER_LEFT);
		ap.add(borderLeft);
		
		BorderHTML borderRight = new BorderHTML(BORDERS_RED);
		borderRight.setStyleName(STYLE__CALENDAR_DAY_RED_BORDER_RIGHT);
		ap.add(borderRight);
	}
	
	
	
	//style do black border
	private static final String STYLE__CALENDAR_DAY_BLACK_BORDER_TOP = "blackBorderTop";
	private static final String STYLE__CALENDAR_DAY_BLACK_BORDER_BOTTOM = "blackBorderBottom";
	private static final String STYLE__CALENDAR_DAY_BLACK_BORDER_LEFT = "blackBorderLeft";
	private static final String STYLE__CALENDAR_DAY_BLACK_BORDER_RIGHT = "blackBorderRight";
	
	public static void addBlackDashedBorders(AbsolutePanel ap) {
		BorderHTML borderTop = new BorderHTML(BORDERS_BLACK);
		borderTop.setStyleName(STYLE__CALENDAR_DAY_BLACK_BORDER_TOP);
		ap.add(borderTop);
		
		BorderHTML borderBottom = new BorderHTML(BORDERS_BLACK);
		borderBottom.setStyleName(STYLE__CALENDAR_DAY_BLACK_BORDER_BOTTOM);
		ap.add(borderBottom);
		
		BorderHTML borderLeft = new BorderHTML(BORDERS_BLACK);
		borderLeft.setStyleName(STYLE__CALENDAR_DAY_BLACK_BORDER_LEFT);
		ap.add(borderLeft);
		
		BorderHTML borderRight = new BorderHTML(BORDERS_BLACK);
		borderRight.setStyleName(STYLE__CALENDAR_DAY_BLACK_BORDER_RIGHT);
		ap.add(borderRight);
	}
	
	
	//style do blue border
	private static final String STYLE__CALENDAR_DAY_BLUE_BORDER_TOP = "blueBorderTop";
	private static final String STYLE__CALENDAR_DAY_BLUE_BORDER_BOTTOM = "blueBorderBottom";
	private static final String STYLE__CALENDAR_DAY_BLUE_BORDER_LEFT = "blueBorderLeft";
	private static final String STYLE__CALENDAR_DAY_BLUE_BORDER_RIGHT = "blueBorderRight";
	
	public static void addBlueDashedBorders(AbsolutePanel ap) {
		BorderHTML borderTop = new BorderHTML(BORDERS_BLUE);
		borderTop.setStyleName(STYLE__CALENDAR_DAY_BLUE_BORDER_TOP);
		ap.add(borderTop);
		
		BorderHTML borderBottom = new BorderHTML(BORDERS_BLUE);
		borderBottom.setStyleName(STYLE__CALENDAR_DAY_BLUE_BORDER_BOTTOM);
		ap.add(borderBottom);
		
		BorderHTML borderLeft = new BorderHTML(BORDERS_BLUE);
		borderLeft.setStyleName(STYLE__CALENDAR_DAY_BLUE_BORDER_LEFT);
		ap.add(borderLeft);
		
		BorderHTML borderRight = new BorderHTML(BORDERS_BLUE);
		borderRight.setStyleName(STYLE__CALENDAR_DAY_BLUE_BORDER_RIGHT);
		ap.add(borderRight);
	}
	
	
	public static void removeAllBorders(AbsolutePanel ap, int borderSort) {
		for (int i = ap.getWidgetCount()-1; i >= 0; i--) {
			Widget w = ap.getWidget(i);
			if (w instanceof BorderHTML) {
				BorderHTML border = (BorderHTML) w;
				if (border.getBorderSort() == borderSort) {
					border.removeFromParent();
				}
			}
		}
	}
	
	
	
}

class BorderHTML extends HTML {
	private int borderSort;

	public BorderHTML(int borderSort) {
		this.borderSort = borderSort;
	}

	public int getBorderSort() {
		return borderSort;
	}
}
